// subpackage/pages/relief/detail.js
import requestUtil from '../../../baseRequest'
import requestUrls from '../../../requestUrl'
let openid = wx.getStorageSync('openid')
Page({

  /**
   * 页面的初始数据
   */
  data: {
    rescueApplyOrder:{

    },
    responsibility:[],
    medicalCertificate:[],
    activeNames:'1',
    showUpload:false,
  },
  onChange(event){
    this.setData({
      activeNames: event.detail
    });
  },
  getById(){
    const {orderId} = this.data;
    let formData = {
      openId:openid,
      criteria:{
        id:orderId,
      }
    };
    requestUtil.postRequest(requestUrls.rescueApply.getById, formData, (res) => {
      if(!res.hasError){
        let rescueApplyOrder = res.result;
        let imageList = rescueApplyOrder.imageList || [];
        let responsibility = [],medicalCertificate=[];
        if(imageList.length>0){
          imageList.forEach(image=>{
            if(image.imageTypeId==="ACCIDENT_CONFIRMATION"){
              responsibility.push({...image,url:requestUrls.baseImagePrefixUrl + image.imageUrl});
            }
            if(image.imageTypeId==="MEDICAL_CERTIFICATE"){
              medicalCertificate.push({...image,url:requestUrls.baseImagePrefixUrl + image.imageUrl});
            }
          })
        };
        this.setData({
          rescueApplyOrder,
          responsibility,
          medicalCertificate
        });
      }
    })

  },
  previewImage(event){
    wx.previewImage({
      urls: [event.currentTarget.dataset.imgurl],
    })
  },
  reEdit(){
    wx.navigateTo({
      url: '/subpackage/pages/relief/index?orderId='+this.data.orderId,
    })
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    const {orderId} = options;
    this.setData({
      orderId,
    })
    this.getById();
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})